var utils = utils || {};

/**
 * @public
 * 创建骨骼动画
 * @param {String} path 骨骼动画路径
 * @param {Number} rate 骨骼动画帧率，引擎默认为30，一般传24
 */
utils.createSkeleton = function (path, rate) {
    var png = Laya.loader.getRes(path + ".png");
    var sk  = Laya.loader.getRes(path + ".sk");
    if(!png || !sk){return null;}

    var templet = new Laya.Templet();
        templet.parseData(png, sk, rate);

    return templet.buildArmature();
}

//获取字符串长度，支持中文
utils.getStringLength = function(str){
    return ("" + str.replace(/[^\x00-\xff]/gi,"ox")).length;
}

utils.cutStr = function (text, length) {
    text = text + "";
    var reg = /[^\x00-\xff]/g;
    if(text.replace(reg, "mm").length <= length){return text;}
    var m = Math.floor(length / 2);
    for(var i = m; i < text.length; i++){
        if(text.substr(0, i).replace(reg, "mm").length >= length){
            return text.substr(0, i) + "...";
        }
    }
    return text;
}
utils.getUrlParam = function(name){
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    
    if(r != null){
        return unescape(r[2]);
    }
    
    return null;
}